package cn.middle.remote.handler.decodec;

import io.netty.buffer.ByteBuf;

public final class CodecUtil {
	
	private CodecUtil() {}
	
	public static boolean checkLength(ByteBuf in,int length,int beginIndex) {
		if(in.readableBytes() < length) {
			in.readerIndex(beginIndex);
			return false;
		}
		return true;
	}
	
	public static String context(ByteBuf in,int length) {
		byte[] data = new byte[length];
		in.readBytes(data);
		return new String(data);
	}
	
	public static byte[] data(ByteBuf in,int length) {
		byte[] data = new byte[length];
		in.readBytes(data);
		return data;
	}

}
